﻿using Dapper;
using Management.Systeam.Domaina;
using MediatR;
using System.Text;
using Warehouse.Api.Read.AGCation.Command;
using Warehouse.Domian.Model;
using Warehouse.ErrorCode;
using Warehouse.Infrastructrue.Implenment;

namespace Warehouse.Api.Read.AGCation.Hanlder
{
    public class GetRolesCommandHanlder : IRequestHandler<GetRolesCommand, ApiResult<List<Users>>>
    {
        DbContext db;
        ILogger<GetRolesCommandHanlder> logger;

        public GetRolesCommandHanlder(DbContext db, ILogger<GetRolesCommandHanlder> logger)
        {
            this.db = db;
            this.logger = logger;
        }
        /// <summary>
        /// 获取经办人下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>

        public   async  Task<ApiResult<List<Users>>> Handle(GetRolesCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<Users>> result = new ApiResult<List<Users>>();
            try
            {
                var sqlBuilder = new StringBuilder();
                sqlBuilder.Append(@"SELECT 
                                        Id,
                                        User_Name
                                        FROM users WHERE 0=0");
                var sql = await db.DapperConnection.QueryAsync<Users>(sqlBuilder.ToString());
                result.Code = ApiEume.Success;
                result.Msg = "获取用户下拉框成功";
                result.Data = sql.ToList();
                
            }
            catch (Exception ex)
            {

            }
            return result;
        }
    }
}
